import datetime
from dateutil.relativedelta import relativedelta
from Node import Node
class Deadline():
    def __init__(self):
        self.deadline = datetime.datetime.now()

    def SetDatetime(self,inputdatetime):
        '''
        设置时间
        
        Args:
            inputdatetime: 输入时间，类型是datetime.datetime，或者一个长度为7的整数list，分别对应年月周日时分秒.
        Return:
            None
        '''
        if isinstance(inputdatetime,datetime.datetime):
            self.deadline = inputdatetime
        elif isinstance(inputdatetime,list):
            assert(len(inputdatetime)==7)
            self.deadline += relativedelta(years=inputdatetime[0],
                                        months=inputdatetime[1],
                                        weeks=inputdatetime[2],
                                        days=inputdatetime[3],
                                        hours=inputdatetime[4],
                                        minutes=inputdatetime[5],
                                        seconds=inputdatetime[6])

        else:
            print("wrong type input!")

    def GetDatetime(self):
        return self.deadline
    
class Task():
    def __init__(self,title,deadline,importance=False,emergence=False,done=0):
        self.title = title
        self.importance = importance
        self.emergence = emergence
        self.done = done
        tmpdeadline = Deadline()
        tmpdeadline.SetDatetime(deadline)
        self.deadline = tmpdeadline.GetDatetime()
        self.nodelist = []

    def AddNode(self,node,process=None):
        self.nodelist.append(node)
        if (process!=None and process<=1 and process>0):
            self.done = process
